package com.kehao.others.tencent;

import java.util.Scanner;

public class Question3 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[] charArray = sc.next().toCharArray();
        int dp[] = new int[charArray.length+1];
        boolean flag = false;
        int minDp = Integer.MAX_VALUE;
        for (int i = 0; i < charArray.length; i++) {
            if(charArray[i]=='1'){
                dp[0]=dp[0]+(i+1);
            }
        }
        for (int pos = 1; pos < dp.length; pos++) {
            int index = pos -1;
            if(charArray[index]=='0'){
                if(flag == true){
                    dp[pos] = dp[pos-1] + pos;
                }else {
                    dp[pos] = dp[pos-1] - pos;
                }
            }else {
                if(flag == true){
                    dp[pos] = dp[pos-1] + pos;
                }else {
                    dp[pos] = dp[pos-1] - pos;
                }
            }
            if(dp[pos]<0){
                flag = ! flag;
                dp[pos] = - dp[pos];
            }
            minDp = Integer.min(minDp,dp[pos]);
        }
        System.out.println(minDp);
    }
}
